package log

import (
	"io"
	"os"

	"file_explorer/common/util"
)

const (
	timeFormat = "2006-01-02 15:04:05.000"
)

type Logger interface {
	Debug(string, ...any)
	Info(string, ...any)
	Warn(string, ...any)
	Error(string, ...any)
}

var (
	logger    Logger
	newLogger = NewZeroLogger
)

func init() {
	if util.IsDevEnv() {
		logger = newLogger(os.Stdout)
	}
}

func UpdateLogger(writer io.Writer) {
	if writer == nil && util.IsDevEnv() {
		writer = os.Stdout
	}
	logger = newLogger(writer)
}

func Debug(format string, args ...any) {
	if logger == nil {
		return
	}
	logger.Debug(format, args...)
}

func Info(format string, args ...any) {
	if logger == nil {
		return
	}
	logger.Info(format, args...)
}

func Warn(format string, args ...any) {
	if logger == nil {
		return
	}
	logger.Warn(format, args...)
}

func Error(format string, args ...any) {
	if logger == nil {
		return
	}
	logger.Error(format, args...)
}
